package cn.xeblog.forward.handler;

import cn.xeblog.forward.entity.Message;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * @author eleven
 * @date 2024/12/16 9:31
 * @apiNote 只接受Message类型
 */
@Slf4j
public class ForwardMessagesHandler extends SimpleChannelInboundHandler<Message> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
        log.info("收到消息：{}", msg);
        ctx.writeAndFlush(msg);
    }

    /**
     * channel连接时触发
     * @param ctx
     * @throws Exception
     */
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        log.info("client active");
        super.channelActive(ctx);
    }

    /**
     * channel断开时触发
     * @param ctx
     * @throws Exception
     */
    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        log.info("client inactive");
        super.channelInactive(ctx);
    }
}
